//
//  ViewController.m
//  AVSpeechSynthesizer
//
//  Created by hanxiao on 2017/5/25.
//  Copyright © 2017年 hanxiao. All rights reserved.
//

#import "ViewController.h"
@import AVFoundation;
@interface ViewController ()<AVSpeechSynthesizerDelegate>
- (IBAction)beginAction:(id)sender;
- (IBAction)pauseAction:(id)sender;
- (IBAction)continueAction:(id)sender;

@end

@implementation ViewController
{
    AVSpeechSynthesizer *synthesizer;

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)beginAction:(id)sender {
    
    NSString *string = @"窗前明月光，疑是地上霜，举头望明月，低头思故乡！";
    
    AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:string];
    
    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
    
    //设置语速
    utterance.rate = 0.3;
    //设置音量
    //    utterance.volume = 0.6;
    
    synthesizer = [[AVSpeechSynthesizer alloc] init];
    
    synthesizer.delegate = self;
    
    
    [synthesizer speakUtterance:utterance];
}

- (IBAction)pauseAction:(id)sender
{
    
    [synthesizer pauseSpeakingAtBoundary:YES];
}

- (IBAction)continueAction:(id)sender
{
    [synthesizer continueSpeaking];
}
@end
